package tech.aistar.controller.qiniuyuntest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import tech.aistar.util.QiniuUtil;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * Created by longye on 2019/10/3.
 */

@Controller
@RequestMapping("/test")
public class QiNiuTestController {
    @Autowired
    private QiniuUtil qiniuUtil;
//    MultipartFile[] myfile=new MultipartFile[2];
    @RequestMapping("/upload")
    @ResponseBody
    public Map upload(MultipartFile[] myfile) {
        Map<String,String> map = new HashMap<>();
        try {
            for (int i = 0; i <myfile.length ; i++) {
                String imgUrl = qiniuUtil.upload(myfile[i].getBytes(),myfile[i].getOriginalFilename());
                map.put("imgUrl"+i, imgUrl);
                System.out.println(imgUrl);
            }
        } catch (IOException e) {
            e.printStackTrace();
            map.put("imgUrl", null);
        }
        //因为要作为结果返回
        return map;
    }
}
